<!--
 * @Author: Ming shi gang
 * @Date: 2019-09-10 19:28:53
 * @LastEditors: Ming shi gang
 * @LastEditTime: 2019-09-13 15:52:56
 -->
<template>
  <div class="searchMember">
    <div class="search_menu">
      <div class="search_cont">
        <div class="search_go_back fl" @click="go_back"></div>
        <div class="search_input fl">
          <input type="text" class="search_key" v-focus v-model="keyword" placeholder="请输入你要搜索的用户名" />
        </div>
        <div class="search_search fr" @click="search">搜索</div>
        <div class="clear"></div>
      </div>
    </div>
    <div class="search_list" id="search-list">
      <ul>
        <li @click="open(index)" v-for="(item,index) in searchList" :key="index">
          <div class="li-left">
            <div class="member_img">
              <img v-if="item.head_pic" :src="item.head_pic" />
              <img v-else src="/static/picture/head_img.png" />
            </div>
            <div class="member_info">
              <div class="member_name">{{item.nickname}}</div>
              <div class="member_time">{{item.create_time}}</div>
            </div>
          </div>
          <div class="team_simple">
            <div class="team_simple-left">
              <div class="simple_num">邀请{{item.child_num}}人</div>
              <div class="simple_from">邀请人：{{item.parent_nickname}}</div>
            </div>
            <span class="team_content_go"></span>
          </div>
        </li>
      </ul>
      <div class="bottom" v-if="searchList.length>0 && !isGetMore">已经到底啦</div>
    </div>
    <div class="container" v-if="container" @click="close"></div>
    <div class="container_info" v-if="container">
      <div class="info_img">
        <img v-if="detail.head_pic" :src="detail.head_pic" />
        <img v-else src="/static/picture/head_img.png" />
      </div>
      <div class="info_name">
        <span>{{detail.nickname}}</span>
        <img v-if="+detail.level===1" src="/static/picture/one.png" />
        <img v-if="+detail.level===2" src="/static/picture/two.png" />
        <img v-if="+detail.level===3" src="/static/picture/three.png" />
        <img v-if="+detail.level===4" src="/static/picture/four.png" />
      </div>
      <div class="info_invite">
        邀请码：
        <span id="cp_code">{{detail.spread_code}}</span>
        <span data-clipboard-target="#cp_code" @click="doCopy" class="info_copy under_copy">复制</span>
      </div>
      <div class="info_sum">
        <div class="sum_wait">
          <div class="num">{{detail.integral}}</div>
          <div class="wait">累计积分</div>
        </div>
        <div class="sum_add">
          <div class="num">{{detail.total_earn}}</div>
          <div class="add">累计金额</div>
        </div>
      </div>
      <div class="info_close" @click="close">关闭</div>
    </div>
    <div class="no-fans" v-if="searchList.length===0&&!isGetMore">
      <img src="/static/picture/no_fans.png" />
      <div>目前暂无粉丝</div>
    </div>
  </div>
</template>
<script>
import $ from "jquery";
import Clipboard from "clipboard";
export default {
  name: "SearchMember",
  data() {
    return {
      isStart: false,
      container: false,
      keyword: "",
      searchList: [],
      limit: 20,
      page: 1,
      token: "",
      isSending: false, // 是否正在加载
      isGetMore: true, // 是否还有更多
      detail: {
        level: "",
        nickname: "",
        spread_code: "",
        integral: "",
        total_earn: "",
        head_pic: ""
      }
    };
  },
  directives: {
    focus: {
      // 指令的定义
      inserted: function(el) {
        el.focus();
      }
    }
  },
  created() {
    document.title = "粉丝搜索";
    if (localStorage.token) {
      this.token = localStorage.getItem("token");
    }
  },
  mounted() {
    document.body.addEventListener("touchmove", () => {
      let element = $("#search-list");
      if (this.searchList.length === 0) {
        return;
      }
      let win = $(window);
      if (
        element.offset().top + element.height() <=
        win.height() + win.scrollTop()
      ) {
        this.getTeamSearch();
      }
    });
  },
  methods: {
    close() {
      this.container = false;
    },
    doCopy() {
      let clipboard = new Clipboard(".under_copy");
      clipboard.on("success", e => {
        Toast("复制成功");
        clipboard.destroy();
      });
      clipboard.on("error", e => {
        Toast("复制失败");
        clipboard.destroy();
      });
    },
    open(index) {
      this.container = true;
      this.detail.level = +this.searchList[index].level;
      this.detail.nickname = this.searchList[index].nickname;
      this.detail.spread_code = this.searchList[index].spread_code;
      this.detail.integral = this.searchList[index].integral;
      this.detail.total_earn = this.searchList[index].total_earn;
      this.detail.head_pic = this.searchList[index].head_pic;
    },
    getKey(e) {
      this.keyword = e;
      this.$router.push({ path: "/possess", query: { keyword: e } });
    },
    go_back() {
      this.$router.go(-1);
    },
    search() {
      if (this.keyword === "") {
        Toast("请先输入搜索内容");
        return;
      }
      this.isSending = false;
      this.isGetMore = true;
      this.searchList = [];
      this.page = 1;
      this.getTeamSearch();
    },
    //列表
    getTeamSearch() {
      var that = this;
      if (this.isSending || !this.isGetMore) {
        return;
      }
      this.isSending = true;
      Indicator.open();
      this.$axios
        .get("/v1/user/getTeamSearch", {
          params: {
            keyword: this.keyword,
            page: this.page,
            limit: this.limit
          },
          headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            Authorization: "bearer " + this.token
          }
        })
        .then(res => {
          if (res.data.code == 200) {
            Indicator.close();
            // this.isStart = true;
            this.page++;
            that.searchList = that.searchList.concat(res.data.data);
            if (res.data.data.length < this.limit) {
              this.isGetMore = false;
            }
            this.isSending = false;
          } else {
            Toast(res.data.msg);
          }
        });
    }
  }
};
</script>
<style lang="less" scoped>
.searchMember {
  padding-top: 120px;
  box-sizing: border-box;
  background: #f8f8f8;
  height: 100vh;
}
.no-fans {
  position: fixed;
  width: 460px;
  height: 420px;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  img {
    width: 100%;
    height: 100%;
  }
  > div {
    color: #c6c6c6;
    text-align: center;
    font-size: 22px;
  }
}
// .bac {
//   background: #f8f8f8;
//   width: 100%;
//   height: 20px;
// }
.search_input {
  width: 76%;
}
.search_menu {
  width: 100%;
  height: 100px;
  line-height: 68px;
  padding: 20px 0;
  background: #ffffff;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2;
  box-sizing: border-box;
}
.search_menu .search_cont {
  width: 96%;
  margin: 0 auto;
}
.search_key {
  width: 100%;
  height: 65px;
  line-height: 68px;
  border: none;
  border-radius: 34px;
  font-size: 28px;
  background: #f8f8f8 url(/static/images/glass.png) no-repeat right 20px center;
  background-size: 40px 40px;
  text-indent: 26px;
  outline: none;
}
.search_go_back {
  width: 48px;
  height: 48px;
  background: url(/static/images/team_go_back.png) no-repeat left center;
  background-size: 100% 100%;
  margin-right: 2%;
  margin-top: 12px;
}
.search_search {
  width: 10%;
  line-height: 68px;
  font-size: 28px;
  color: #000;
}
.search_list {
  background: white;
  // margin-top: 20px;
  min-height: calc(100vh - 100px - 20px);
  border-radius: 80px 80px 0 0;
  .bottom {
    font-size: 24px;
    line-height: 80px;
    text-align: center;
    width: 100%;
  }
}
.search_list ul {
  width: 100%;
  background: #fff;
}
.search_list li {
  width: 698px;
  height: 144px;
  margin: 0 auto;
  border-bottom: 2px solid #f2f2f2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.li-left {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .member_img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 20px;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
  .member_info {
    .member_name {
      font-size: 28px;
      color: #000000;
      // padding-top: 34px;
    }
    .member_time {
      font-size: 20px;
      color: #000000;
      margin-top: 10px;
    }
  }
}
.team_simple {
  font-size: 20px;
  color: #9b9b9b;
  display: flex;
  justify-content: flex-start;
  height: 100%;
  align-items: center;
  .simple_from {
    margin-top: 12px;
  }
  .team_content_go {
    width: 24px;
    height: 24px;
    border-bottom: 1px solid #c6c6c6;
    border-right: 1px solid #c6c6c6;
    top: 60px;
    left: 170px;
    display: inline-block;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
  }
}
.container {
  position: fixed;
  width: 100%;
  height: 100%;
  background: #989898;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.3;
}
.container_info {
  width: 500px;
  height: 516px;
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  opacity: 1;
  z-index: 4;
  padding-top: 24px;
  border-radius: 20px;
}
.info_img {
  width: 80px;
  height: 80px;
  margin: 0 auto;
  border-radius: 50%;
}
.info_img img {
  width: 100%;
  margin: 0 auto;
  border-radius: 50%;
}
.container_info .info_name {
  font-size: 28px;
  color: #000000;
  text-align: center;
  line-height: 68px;
}
.container_info .info_name img {
  width: 60px;
  height: 28px;
}
.container_info .info_invite {
  font-size: 24px;
  color: #000000;
  text-align: center;
}
.container_info .info_invite span {
  padding: 0 6px;
  color: #4a4a4a;
  border-radius: 8px;
  border: 2px solid #4a4a4a;
  margin-left: 30px;
}
.container_info .info_sum {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  justify-items: center;
  text-align: justify;
  width: 380px;
  margin: 0 auto;
  border-top: 2px solid #f2f2f2;
  margin-top: 28px;
  padding-top: 30px;
}
.info_sum .sum_wait {
  width: 190px;
  text-align: center;
}
.info_sum .sum_add {
  width: 190px;
  text-align: center;
}
.info_sum .num {
  font-size: 36px;
  color: #000000;
}
.info_sum .wait,
.info_sum .add {
  color: #333334;
  font-size: 28px;
}
.info_close {
  width: 330px;
  height: 92px;
  border-radius: 46px;
  background: #ffe514;
  line-height: 92px;
  text-align: center;
  font-size: 32px;
  color: #333334;
  margin: 0 auto;
  margin-top: 50px;
}
</style>
